var app = getApp();
var Ajax=require("../../utils/ajax.js")
var Login = require("../../utils/login.js")
Page({
  data:{
    canIUse:wx.canIUse('button.open-type.getUserInfo')
  },
  onLoad(){
    var self=this;
    Login.checkLogin(()=>{
      Ajax.AsyncGet("/mesh/get_user_info/", null, (data) => {
        if (!data.userinfo.avatarurl){
          wx.getSetting({
            success: (res) => {
              if (res.authSetting['scope.userInfo']) {
                wx.getUserInfo({
                  success:(res)=> self.setUserInfo(res.userInfo)
                })
              }
            }
          });
        } else wx.switchTab({url: '/pages/meshown/meshown'});
      })
    });
  },
  bindgetUserInfo:function(e){
    if (e.detail.userInfo){
      this.setUserInfo(e.detail.userInfo);
    }else{
      wx.showToast({
        title: '只有授权登录之后才能使用小程序功能哦！',
        duration: 2000
      })
    }
  },
  setUserInfo(userInfo){
    Ajax.AsyncPost("/mesh/set_user_info/", userInfo, () => {
      wx.switchTab({
        url: '/pages/meshown/meshown',
      })
    });
  }
})